﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using KPIS.GERP.ESS.APP.App_UI.Reports;
//using KPIS.GERP.ESS.MODEL;
//using KPIS.GERP.ESS.IBLL;
//using KPIS.GERP.ESS.BLL;
using KPIS.GERP.ESS.APP.App_UI.Commons;
using _WebShared.Classes;

namespace KPIS.GERP.ESS.APP.App_UI.Forms
{
    public partial class ViewReport : System.Web.UI.Page
    {
        Main main = new Main();

        public void Page_Load(object sender, EventArgs e)
        {
            //string ReportName = Request.QueryString["name"];
            //string Seq = Session["ReportSeq"].ToString();

            //LoadReport(ReportName, Seq);
        }

        protected void LoadReport(string ReportName, string Seq)
        {
            Session["ReportSeq"] = Seq;
            switch (ReportName)
            {
                case "Receipt":
                    LoadReceipt(Seq);
                    break;
                case "ProjectOperation":
                    LoadProjectOperation(Seq);
                    break;
                case "ProjectOperationEdit":
                    LoadProjectOperationEdit(Seq);
                    break;
                case "MoneyReqContractNew":
                    LoadMoneyReqContracts(Seq);
                    break;
                case "SumUpPayment":
                    LoadSumUpPayment(Seq);
                    break;
                case "SumUpReceive":
                    LoadSumUpReceive(Seq);
                    break;
            }
        }

        protected void LoadReceipt(string Seq)
        {
            //Receipt Receipt1 = new Receipt();
            //IBLL_FIM_Receives r = new B_FIM_Receives();
            //Receipt1.SetDataSource(r.Report_Receipt(Seq));
            //CrystalReportViewer1.ReportSource = Receipt1;
        }

        protected void LoadProjectOperation(string Seq)
        {
            ProjectOperation ProjectOperation1 = new ProjectOperation();
            BGM_ProjectOperation.BGM_ProjectOperation op = new BGM_ProjectOperation.BGM_ProjectOperation();
            ProjectOperation1.SetDataSource(op.Report_ProjectOperation(Seq));
            ProjectOperation1.OpenSubreport("ProjectOperationSub.rpt");
            ProjectOperation1.Subreports[0].SetDataSource(op.SubReport_ProjectOperation(Seq));
            string strProductList = op.GetOptionProduct(Seq);
            ProjectOperation1.SetParameterValue(0, strProductList);
            ProjectOperation1.SetParameterValue(1, main.GetSystemJobsiteName());
            CrystalReportViewer1.ReportSource = ProjectOperation1;
        }

        protected void LoadProjectOperationEdit(string Seq)
        {
            ProjectOperation ProjectOperation1 = new ProjectOperation();
            BGM_ProjectOperation.BGM_ProjectOperation op = new BGM_ProjectOperation.BGM_ProjectOperation();
            ProjectOperation1.SetDataSource(op.Report_ProjectOperationEdit(Seq));
            ProjectOperation1.OpenSubreport("ProjectOperationSub.rpt");
            ProjectOperation1.Subreports[0].SetDataSource(op.SubReport_ProjectOperationEdit(Seq));
            string strProductList = op.GetOptionProduct(Seq);
            ProjectOperation1.SetParameterValue(0, strProductList);
            ProjectOperation1.SetParameterValue(1, main.GetSystemJobsiteName());
            ProjectOperation1.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "ProjectEdit.pdf");
            //CrystalReportViewer1.ReportSource = ProjectOperation1;
        }

        protected void LoadMoneyReqContracts(string Seq)
        {
            MoneyReqContractNew MoneyReqContracts1 = new MoneyReqContractNew();
            FIM_MoneyRequests.FIM_MoneyRequests contract = new FIM_MoneyRequests.FIM_MoneyRequests();
            DataTable dtb = contract.Report_Contract(Seq);
            MoneyReqContracts1.SetDataSource(dtb);
            MoneyReqContracts1.OpenSubreport("MoneyReqContractsSub.rpt");
            MoneyReqContracts1.Subreports[0].SetDataSource(contract.Report_ContractSub(Seq));

            string strMoneyTextThai = main.MoneyTextThai(Convert.ToDouble(dtb.Rows[0]["bath_amount"] ?? 0));
            MoneyReqContracts1.SetParameterValue("param0", strMoneyTextThai);
            MoneyReqContracts1.SetParameterValue("param0", strMoneyTextThai, "MoneyReqContractsSub.rpt");
            //CrystalReportViewer1.Font.Name = "BrowalliaUPC";
            CrystalReportViewer1.ReportSource = MoneyReqContracts1;
        }

        protected void LoadMoneyReqContractsRDLC(string Seq)
        {
            //FIM_MoneyRequests.FIM_MoneyRequests contract = new FIM_MoneyRequests.FIM_MoneyRequests();
            //ReportViewer1.LocalReport.DataSources.Clear();
            //ReportViewer1.LocalReport.ReportPath = @"App_UI\Reports\MoneyReqContract.rdlc";
            //ReportDataSource reportDSHeader = new ReportDataSource("DS_Reports_MoneyReqContract", contract.Report_Contract(Seq));
            //ReportDataSource reportDSDetail = new ReportDataSource("DS_Reports_MoneyReqContractSub", contract.Report_ContractSub(Seq));
            //ReportViewer1.LocalReport.DataSources.Add(reportDSHeader);
            //ReportViewer1.LocalReport.DataSources.Add(reportDSDetail);
            //ReportViewer1.LocalReport.Refresh();
        }

        protected void LoadSumUpPayment(string Seq)
        {
            //SumUpPayment SumUpPayment1 = new SumUpPayment();
            //IBLL_FIM_Payments pay = new B_FIM_Payments();
            //SumUpPayment1.SetDataSource(pay.Report_SumUpPayment(Seq));
            //CrystalReportViewer1.ReportSource = SumUpPayment1;
        }

        protected void LoadSumUpReceive(string Seq)
        {
            //SumUpReceive SumUpReceive1 = new SumUpReceive();
            //IBLL_FIM_Receives rec = new B_FIM_Receives();
            //SumUpReceive1.SetDataSource(rec.Report_SumUpReceive(Seq));
            //CrystalReportViewer1.ReportSource = SumUpReceive1;
        }

        protected void CrystalReportViewer1_Init(object sender, EventArgs e)
        {
            string ReportName = Request.QueryString["name"];
            string Seq = Session["ReportSeq"].ToString();

            LoadReport(ReportName, Seq);
        }
    }
}
